/*
 * Copyright 2008-2010 GP Software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 * Launcher.java | Created on Sep 28, 2010
 */
package org.gpsoftware.xlsMerge;

import org.gpsoftware.xlsMerge.dataMerger.DataMerger;
import org.gpsoftware.xlsMerge.dataMerger.DataMergerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * The launcher class
 *
 * @author Paul Augustine C. Mendoza
 */
public class Launcher {

    private static final Logger LOGGER = LoggerFactory
            .getLogger(Launcher.class);

    public static void main(String[] args) {
        validateArguments(args);
        File inputFile = new File(args[0]);
        DataMerger merger = DataMergerFactory.getDataMerger(FileType.XLS);
        try {
            merger.merge(inputFile, args[1]);
        } catch (MergeException me) {
            LOGGER.error("Error in merging " + me.getInputFile().getName(), me);
        } catch (Exception e) {
            LOGGER.error("Generic error in merging " + inputFile.getName(), e);
        }
    }

    private static void validateArguments(String[] args) {
        if (!hasValidParamCount(args.length)) {
            throw new IllegalArgumentException("Invalid parameters.");
        }
    }

    private static boolean hasValidParamCount(int count) {
        return count == 2;
    }

}
